<?php
use yii\widgets\LinkPager;
use yii\widgets\Pjax;
use yii\helpers\Url;
use common\service\UtilService ;

$pageName = "系统参数";
$controller = Yii::$app->controller->id;
$action = Yii::$app->controller->action->id;
$this->title = $pageName . "-" . Yii::$app->params['webname'];
$this->params['breadcrumbs'][] = $pageName;
$this->params['display_name'] = $pageName;
//属性状态
$set_status = [0=>"停用",1=>"可用"];

$isMobile = UtilService::isMobile() ;
if($isMobile==true){
    $css = "table-responsive" ;
}else{
    $css = "" ;
}

?>
<?php Pjax::begin(); ?>
<div class="row">
    <div class="col-md-12">
        <div class="nav-tabs-custom">
            <div class="tab-content">
                <div class="form-group">
                    <button id="add_new" class="btn btn-primary btn-xs pull-right btn-hide button-add-contral" title="添加系统参数" type="button"><i class="fa fa-plus"></i>添加</button>
                </div>
            </div>
            <div class="tab-content">
                <div class="tab-pane active">
                    <div class="box-body <?=$css?> no-padding">
                        <table class="table table-bordered table-striped table-condensed">
                            <tbody>
                                <tr>
                                    <th>标识</th>
                                    <th>参数名</th>
                                    <th width="600px">控制值</th>
                                    <th width="200px">描述</th>
                                    <th width="200px">备注</th>
                                    <th>状态</th>
                                    <th>修改时间</th>
                                    <th>操作</th>
                                </tr>
                                <?php foreach ($data as $value): ?>
                                    <tr>
                                        <td><?= $value['unique_mark'] ?></td>
                                        <td><?= $value['name'] ?></td>
                                        <td><?= $value['value'] ?></td>
                                        <td><?= $value['description'] ?></td>
                                        <td><?= $value['remark'] ?></td>
                                        <td><?= isset($set_status[$value['status']])?$set_status[$value['status']]:''; ?></td>
                                        <td><?= $value['update_time'] ?></td>
                                        <td>
                                            <button id="edit-contral" class="btn btn-primary btn-xs edit btn-hide button-edit-contral" title="编辑系统参数" type="button" data-id="<?= $value['id']?>">编辑</button>
                                            <button class="btn btn-danger btn-xs del-contral-btn btn-hide button-del-contral" data-id="<?= $value['id']?>" type="button">删除</button>
                                        </td>
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="text-center">
                        <?=
                            LinkPager::widget([
                                'firstPageLabel' => '首页',
                                'lastPageLabel' => '末页',
                                'prevPageLabel' => '上一页',
                                'nextPageLabel' => '下一页',
                                'pagination' => $page,
                                'maxButtonCount' => 8,
                            ])
                        ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var contral_id;
    $(function(){
        $("#myModal").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
            $(this).find(".modal-content").children().remove();
        })
    });
    $('#add_new').click(function () {
        var options = {remote: '<?= Url::toRoute('add-contral') ?>'};
        $('#myModal').modal(options)
    });
    $('.edit').click(function () {
        var id = $(this).data('id');
        var options = {remote: '<?= Url::toRoute('edit-contral') ?>' + '?id=' + id};
        $('#myModal').modal(options)
    });
    $('.del-contral-btn').click(function () {
        contral_id = $(this).data('id');
        var tmpHtml = '<div class="modal-header">\n' +
            '                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>\n' +
            '                <h4 class="modal-title">后台管理</h4>\n' +
            '            </div>\n' +
            '            <div class="modal-body">\n' +
            '                <h4>您确定要删除此控制参数吗?</h4>\n' +
            '            </div>\n' +
            '            <div class="modal-footer">\n' +
            '                <button type="button" class="btn btn-default pull-left" data-dismiss="modal">取消</button>\n' +
            '                <button type="button" class="btn btn-default modal-btn-sure button-del-contral-confirm">确认</button>\n' +
            '            </div>';
        $("#myModal").find(".modal-content").html(tmpHtml);
        $('#myModal').modal('show');
    });
    $(document).on('click', '.button-del-contral-confirm', function () {
        var id =  contral_id;
        sendAjax('<?= Url::toRoute('del-contral') ?>', {id:id}, $(this));
    })
</script>
<?php Pjax::end(); ?>
